package com.xiaofei.view;

import com.example.net.R;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView.FindListener;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;

public class ChooseLinkFragment extends Fragment {

	EditText urlet;
	int choose;
	FragmentManager manager;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub

		View layout = inflater.inflate(R.layout.fragment_chooselink, container,
				false);
		RadioGroup rg = (RadioGroup) layout.findViewById(R.id.rg);
		urlet = (EditText) layout.findViewById(R.id.urlet);

		manager = getFragmentManager();
		rg.setOnCheckedChangeListener(new OnCheckedChangeListener() {

			@Override
			public void onCheckedChanged(RadioGroup group, int checkedId) {
				// TODO Auto-generated method stub
				switch (checkedId) {
				case R.id.rb_urlcon:
					choose = 1;

					FragmentTransaction ft = manager.beginTransaction();
					URLConnectFragment fb = new URLConnectFragment();
					Bundle b = new Bundle();
					b.putString("url", urlet.getText().toString());
					fb.setArguments(b);
					ft.replace(R.id.result, fb);
					ft.commit();
					break;
				case R.id.rb_httpclientget:
					choose = 2;
					FragmentTransaction ft2 = manager.beginTransaction();
					HttpGetConFragment fb2 = new HttpGetConFragment();
					Bundle b2 = new Bundle();
					b2.putString("url", urlet.getText().toString());
					fb2.setArguments(b2);
					ft2.replace(R.id.result, fb2);
					ft2.commit();
					break;
				case R.id.rb_httpclientpost:
					choose = 3;
					FragmentTransaction ft3 = manager.beginTransaction();
					HttpPostConFragment fb3 = new HttpPostConFragment();
					Bundle b3 = new Bundle();
					b3.putString("url", urlet.getText().toString());
					fb3.setArguments(b3);
					ft3.replace(R.id.result, fb3);
					ft3.commit();
					break;
				default:
					choose = 4;
					FragmentTransaction ft4 = manager.beginTransaction();
					TrafficStatsFragment fb4 = new TrafficStatsFragment();
					Bundle b4 = new Bundle();
					b4.putString("url", urlet.getText().toString());
					fb4.setArguments(b4);
					ft4.replace(R.id.result, fb4);
					ft4.commit();
					break;
				}
			}

		});
		return layout;
	}

}
